home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / Direct3D / EffectEdit / OptionsView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-27  |  6.5 KB  |  221 lines

  1. // OptionsView.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "EffectEdit.h"
  6. #include "EffectDoc.h"
  7. #include "OptionsView.h"
  8. #include "UIElements.h"
  9. #include "RenderView.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // COptionsView
  19.  
  20. IMPLEMENT_DYNCREATE(COptionsView, CFormView)
  21.  
  22. COptionsView::COptionsView()
  23.     : CFormView(COptionsView::IDD)
  24. {
  25.     //{{AFX_DATA_INIT(COptionsView)
  26.         // NOTE: the ClassWizard will add member initialization here
  27.     //}}AFX_DATA_INIT
  28. }
  29.  
  30. COptionsView::~COptionsView()
  31. {
  32. }
  33.  
  34. void COptionsView::DoDataExchange(CDataExchange* pDX)
  35. {
  36.     CFormView::DoDataExchange(pDX);
  37.     //{{AFX_DATA_MAP(COptionsView)
  38.         // NOTE: the ClassWizard will add DDX and DDV calls here
  39.     //}}AFX_DATA_MAP
  40. }
  41.  
  42.  
  43. BEGIN_MESSAGE_MAP(COptionsView, CFormView)
  44.     //{{AFX_MSG_MAP(COptionsView)
  45.     ON_WM_SIZE()
  46.     ON_CBN_SELCHANGE(IDC_TECHNIQUELIST, OnChangeTechnique)
  47.     ON_CBN_SELCHANGE(IDC_PASSLIST, OnChangePass)
  48.     ON_BN_CLICKED(IDC_SHOWSTATS, OnShowStats)
  49.     ON_BN_CLICKED(IDC_WIREFRAME, OnFillModeChange)
  50.     ON_BN_CLICKED(IDC_SELECTEDPASS, OnChangeRenderPass)
  51.     ON_BN_CLICKED(IDC_NOTEXTURES, OnFillModeChange)
  52.     ON_BN_CLICKED(IDC_WITHTEXTURES, OnFillModeChange)
  53.     ON_BN_CLICKED(IDC_UPTOSELECTEDPASS, OnChangeRenderPass)
  54.     ON_BN_CLICKED(IDC_ALLPASSES, OnChangeRenderPass)
  55.     ON_BN_CLICKED(IDC_RESETCAMERA, OnResetCamera)
  56.     ON_BN_CLICKED(IDC_RENDERCONTINUOUSLY, OnChangeRenderTiming)
  57.     ON_BN_CLICKED(IDC_RENDERONREQUEST, OnChangeRenderTiming)
  58.     ON_BN_CLICKED(IDC_RENDER, OnRender)
  59.     //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61.  
  62. /////////////////////////////////////////////////////////////////////////////
  63. // COptionsView diagnostics
  64.  
  65. #ifdef _DEBUG
  66. void COptionsView::AssertValid() const
  67. {
  68.     CFormView::AssertValid();
  69. }
  70.  
  71. void COptionsView::Dump(CDumpContext& dc) const
  72. {
  73.     CFormView::Dump(dc);
  74. }
  75.  
  76.  
  77. CEffectDoc* COptionsView::GetDocument() // non-debug version is inline
  78. {
  79.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEffectDoc)));
  80.     return (CEffectDoc*)m_pDocument;
  81. }
  82. #endif //_DEBUG
  83.  
  84. /////////////////////////////////////////////////////////////////////////////
  85. // COptionsView message handlers
  86.  
  87. void COptionsView::OnSize(UINT nType, int cx, int cy) 
  88. {
  89.     CFormView::OnSize(nType, cx, cy);
  90. }
  91.  
  92.  
  93. void COptionsView::SetTechniqueNameList( CStringList& techniqueNameList, int iTechniqueCur )
  94. {
  95.     CComboBox* pComboBox = (CComboBox*)GetDlgItem( IDC_TECHNIQUELIST );
  96.     if( pComboBox == NULL )
  97.         return;
  98.  
  99.     pComboBox->ResetContent();
  100.  
  101.     POSITION pos = techniqueNameList.GetHeadPosition();
  102.     while (pos != NULL)
  103.     {
  104.         CString str = techniqueNameList.GetNext(pos);
  105.         pComboBox->AddString( str );
  106.     }
  107.     pComboBox->SetCurSel( iTechniqueCur );
  108.     PostMessage( WM_COMMAND, 
  109.                  MAKEWPARAM(IDC_TECHNIQUELIST, CBN_SELCHANGE), 
  110.                  (LPARAM)GetDlgItem( IDC_TECHNIQUELIST )->GetSafeHwnd() );
  111.     pComboBox->EnableWindow(pComboBox->GetCount() > 1);
  112. }
  113.  
  114.  
  115. void COptionsView::OnChangeTechnique() 
  116. {
  117.     CComboBox* pComboBox = (CComboBox*)GetDlgItem( IDC_TECHNIQUELIST );
  118.     int iTech = pComboBox->GetCurSel();
  119.     if( iTech >= 0 )
  120.     {
  121.         CString strTechName;
  122.         pComboBox->GetLBText( iTech, strTechName );
  123.         CRenderView* pRenderView = GetDocument()->GetRenderView();
  124.         pRenderView->SetTechnique( iTech, strTechName );
  125.  
  126.         CStringList passNameList;
  127.         pRenderView->GetPassNameList( iTech, passNameList );
  128.         SetPassNameList( passNameList, 0 );
  129.     }
  130. }
  131.  
  132. void COptionsView::SetPassNameList( CStringList& passNameList, int iPassCur )
  133. {
  134.     CComboBox* pComboBox = (CComboBox*)GetDlgItem( IDC_PASSLIST );
  135.     if( pComboBox == NULL )
  136.         return;
  137.  
  138.     pComboBox->ResetContent();
  139.  
  140.     POSITION pos = passNameList.GetHeadPosition();
  141.     while (pos != NULL)
  142.     {
  143.         CString str = passNameList.GetNext(pos);
  144.         pComboBox->AddString( str );
  145.     }
  146.     pComboBox->SetCurSel( iPassCur );
  147.     PostMessage( WM_COMMAND, 
  148.                  MAKEWPARAM(IDC_PASSLIST, CBN_SELCHANGE), 
  149.                  (LPARAM)GetDlgItem( IDC_PASSLIST )->GetSafeHwnd() );
  150.     pComboBox->EnableWindow(pComboBox->GetCount() > 1);
  151. }
  152.  
  153.  
  154. void COptionsView::OnChangePass() 
  155. {
  156.     CComboBox* pComboBox = (CComboBox*)GetDlgItem( IDC_PASSLIST );
  157.     int iPass = pComboBox->GetCurSel();
  158.     if( iPass >= 0 )
  159.     {
  160.         CString strPassName;
  161.         pComboBox->GetLBText( iPass, strPassName );
  162.         CRenderView* pRenderView = GetDocument()->GetRenderView();
  163.         pRenderView->SetPass( iPass, strPassName );
  164.     }
  165. }
  166.  
  167. void COptionsView::OnShowStats() 
  168. {
  169.     BOOL bShowStats = IsDlgButtonChecked( IDC_SHOWSTATS );
  170.     GetDocument()->ShowStats( bShowStats );
  171. }
  172.  
  173. void COptionsView::OnInitialUpdate() 
  174. {
  175.     CFormView::OnInitialUpdate();
  176.  
  177.     BOOL bShowStats = GetDocument()->GetShowStats();
  178.     CheckDlgButton( IDC_SHOWSTATS, bShowStats );
  179.     CheckRadioButton( IDC_WIREFRAME, IDC_WITHTEXTURES, IDC_WITHTEXTURES );
  180.     CheckRadioButton( IDC_SELECTEDPASS, IDC_ALLPASSES, IDC_ALLPASSES );
  181.     CheckRadioButton( IDC_RENDERCONTINUOUSLY, IDC_RENDERONREQUEST, 
  182.         ((CEffectEditApp*)AfxGetApp())->RenderContinuously() ? IDC_RENDERCONTINUOUSLY : IDC_RENDERONREQUEST );
  183.     GetDlgItem( IDC_RENDER )->EnableWindow(!((CEffectEditApp*)AfxGetApp())->RenderContinuously() );
  184.  
  185.     OnFillModeChange();
  186.     OnChangeRenderPass();
  187.     OnChangeRenderTiming();
  188. }
  189.  
  190. void COptionsView::OnFillModeChange() 
  191. {
  192.     CRenderView* pRenderView = GetDocument()->GetRenderView();
  193.     pRenderView->SetWireframe( IsDlgButtonChecked( IDC_WIREFRAME ) );
  194.     pRenderView->SetNoTextures( IsDlgButtonChecked( IDC_NOTEXTURES ) );
  195. }
  196.  
  197. void COptionsView::OnChangeRenderPass() 
  198. {
  199.     CRenderView* pRenderView = GetDocument()->GetRenderView();
  200.     pRenderView->SetSelectedPassOnly( IsDlgButtonChecked( IDC_SELECTEDPASS ) );
  201.     pRenderView->SetUpToSelectedPassOnly( IsDlgButtonChecked( IDC_UPTOSELECTEDPASS ) );
  202. }
  203.  
  204. void COptionsView::OnResetCamera() 
  205. {
  206.     CRenderView* pRenderView = GetDocument()->GetRenderView();
  207.     pRenderView->ResetCamera();
  208. }
  209.  
  210. void COptionsView::OnChangeRenderTiming() 
  211. {
  212.     bool bRenderContinuously = (IsDlgButtonChecked( IDC_RENDERCONTINUOUSLY ) != 0);
  213.     ((CEffectEditApp*)AfxGetApp())->SetRenderContinuously( bRenderContinuously );
  214.     GetDlgItem( IDC_RENDER )->EnableWindow( !bRenderContinuously );
  215. }
  216.  
  217. void COptionsView::OnRender() 
  218. {
  219.     AfxGetApp()->GetMainWnd()->SendMessage(WM_COMMAND, ID_VIEW_RENDER);
  220. }
  221.